//
//  LocationModel.swift
//  LocationDemo
//
//  Created by HzS on 2023/2/9.
//

import Foundation
import CoreLocation

struct LocationModel: Codable {
    let latitude: CLLocationDegrees
    let longitude: CLLocationDegrees
    let altitude: CLLocationDistance
    let horizontalAccuracy: CLLocationDistance
    let verticalAccuracy: CLLocationDistance
    let timestamp: Date
    
    var toCLLocation: CLLocation {
        return CLLocation(coordinate: CLLocationCoordinate2D(latitude: latitude, longitude: longitude),
                          altitude: altitude, horizontalAccuracy: horizontalAccuracy, verticalAccuracy: verticalAccuracy, timestamp: timestamp)
    }
    
    init(clLocation: CLLocation) {
        latitude = clLocation.coordinate.latitude
        longitude = clLocation.coordinate.longitude
        altitude = clLocation.altitude
        horizontalAccuracy = clLocation.horizontalAccuracy
        verticalAccuracy = clLocation.verticalAccuracy
        timestamp = clLocation.timestamp
    }
}
